home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / clp.exe / CLPARSER.DOC < prev    next >
Text File  |  1992-09-07  |  31KB  |  795 lines

  1.  
  2.   ___________________________________________________________________________
  3.  
  4.   CLPARSER.TPU                           Copyright (c) 1989-92 Greg Truesdell
  5.   Version 3.2                                      a Turbo Pascal Object Unit
  6.   ___________________________________________________________________________
  7.  
  8.  
  9.   ABOUT THE AUTHOR___________________________________________________________
  10.  
  11.   The author is an Information Technology Specialist at the Education
  12.   Development Centre in Burnaby, BC, Canada.  The EDC is an industrial
  13.   training and development facility which provides state-of-the-art CBT and
  14.   instructor led courses to corporations and governments throught-out Canada,
  15.   The United States, Europe, Middle East and Far East. As a member of the
  16.   BC Tel Group of Companies, the EDC specializes in Telecommunications,
  17.   Mainframe Computer, Personal Computer, Management, Engineering and Sales
  18.   training as well as Educational Development Resources.
  19.  
  20.   The author was trained as an Aviation Electronics Tech. in the US Navy and
  21.   joined the British Columbia Telephone Co. in 1974.  He held positions in
  22.   Test Desk, Teletype/Data (computer maintenance) and Instructor of computer
  23.   technology courses.
  24.  
  25.   The author is currently responsible for the design, implementation and
  26.   support of Database and Office Automation Systems and products used by the
  27.   EDC, and has co-produced their multi-user time tracking and shared project
  28.   reporting system, the automated billing system, the VAX PCSA-based Office
  29.   Automation multi-user menuing system, the information and report
  30.   distribution system and the student registration and confirmation system.
  31.  
  32.   He is a member of a four person team responsible for all computer-based
  33.   information services required by more than 150 networked PC users as well
  34.   as over 100 mainframe SNA and direct access ports.  Languages of choice
  35.   are Clipper, dBase, Vax C, Turbo C and MS C, Turbo C++, Turbo Pascal and
  36.   Assembler.
  37.  
  38.   He lives with his wife of 20 years, Julia, and their two sons, Joe (18)
  39.   and Duncan (17).  Many thanks to Julia for her MUCH patience!
  40.  
  41.  
  42.   INTRODUCTION_______________________________________________________________
  43.  
  44.   CLParser.TPU is a Command Line Parser.  It provides the programmer with
  45.   several pre-defined objects for dealing with command line options and
  46.   switches.  The unit also provides parsing for wildcard filenames, all
  47.   environment variables and simple text parameter files.
  48.  
  49.   The unit provides methods which manipulate lists of items.  The primary
  50.   object is CLPLIST.  The following is the type definition for CLPLIST:
  51.  
  52.     ItemRecordP = ^ItemRecord;
  53.     ItemRecord = Record
  54.  
  55.         Item        :^String;       { parsed item String }
  56.         ItemLen     : Byte;         { length + 2 of item String }
  57.         Posn        : LongInt;      { position }
  58. |       Cargo       : Pointer;      { data record pointer }
  59. |       CargoLen    : LongInt;      { size of data record pointer }
  60.         NextItem    : ItemRecordP;  { pointer to the next node in list }
  61.         PrevItem    : ItemRecordP;  { pointer to previous node in list }
  62.  
  63.     end;
  64.  
  65.     { list is the data structure }
  66.     pClpList = ^clpList;
  67.     clpList = object
  68.  
  69.         firstitem   : ItemRecordP;  { pointer to first record in list }
  70.         currentitem : ItemRecordP;  { pointer to current record in list }
  71.         lastitem    : ItemRecordP;  { pointer to last record in list}
  72.         items       : Word;         { number of items in the list }
  73.         index       : Word;         { current item number }
  74.  
  75.         Constructor Init;
  76.         Destructor  Done;
  77.         Function    Add( add_item: String; locn: LongInt ): Boolean;
  78. |       Function    AddCargo( Add_Item: String; Locn: LongInt;
  79. |           pCargo : Pointer; CargoSize: Word ) : Boolean;
  80.         Function    Next:                                   String;
  81. |       Function    NextCargo( var pCargo : Pointer; var CargoSize : LongInt ) : String;
  82.         Function    Prev:                                   String;
  83. |       Function    PrevCargo( var pCargo : Pointer; var CargoSize : LongInt ) : String;
  84.         Function    Count:                                  Word;
  85.         Function    Position:                               LongInt;
  86.         Procedure   Reset;
  87.     end;
  88.  
  89.     { help is a list of help lines }
  90.     pHelp = ^Help;
  91.     Help = object(clpList)
  92.         ScreenLines : Byte;
  93.         LineCount   : Byte;
  94.  
  95.         Constructor Init( nLines : Byte );
  96.         Function    ReadFile( filename : String ) : Boolean;
  97.         Procedure   Display;
  98.     end;
  99.  
  100.     { argument is a list of arguments }
  101.  
  102.     pArgument = ^Argument;
  103.     Argument = object(clpList)
  104.  
  105.         more    : Boolean;
  106.  
  107.         Constructor Init( LegalChars: CharSet );
  108.         Function    Find( target : String ): String;
  109.         Function    Overflow: Boolean;
  110.  
  111.     end;
  112.  
  113.     { Environ is a list of environment variables }
  114.  
  115.     pEnviron = ^Environ;
  116.     Environ = object(Argument)
  117.  
  118.         Constructor Init;
  119.  
  120.     end;
  121.  
  122.     { wild is a special list of filenames }
  123.  
  124.     { ======================================================== }
  125.     {                                                          }
  126.     { NOTE:  The pWild object calls the AddCargo method using  }
  127.     {        the search record returned by the FindFirst() and }
  128.     {        FindNext() DOS unit procedures.                   }
  129.     {                                                          }
  130.     { ======================================================== }
  131.  
  132.     pWild = ^Wild;
  133.     Wild = object(argument)
  134.  
  135.         Constructor Init( filemask: String; attributes: Word );
  136.  
  137.     end;
  138.  
  139.     { pfile is a special list of parameter file entries }
  140.     pPFile = ^PFile;
  141.     PFile = object(argument)
  142.  
  143.         Constructor Init( filename: String; comment: CharSet );
  144.  
  145.     end;
  146.  
  147.  
  148.   The CLPLIST object can be used to maintain any kind of sequential list of
  149.   strings.  Each item in the list is a pointer to a variable length string
  150.   and a location word.  The location word was primarily provided to register
  151.   where, on the command line, the item was found.  It may also be used to
  152.   mark entries in the list for other reasons.
  153.  
  154.   Version 2.x was restricted to 1024 entries in any one of the objects.  In
  155.   version 3.x, no such restriction applies.  The only restriction is the
  156.   amount of available heap memory.
  157.  
  158.   Since all other objects in this unit are based on this object, and because
  159.   none of these objects add any data instances of their own, the above
  160.   paragraph is true for them also.
  161.  
  162.  
  163.   The following is a list of all objects defined in CLPARSER.TPU:
  164.  
  165.       name(type)  unique methods
  166.       ----------- --------------------------------------------------------
  167.       CLPLIST     Init      : Clear list to initial values (nil).
  168.       (object)    Done      : Erase and reclaim memory used by the list.
  169.                   Add       : Add an item to the list.
  170. |                 AddCargo  : Add an item to the list with cargo.
  171.                   Next      : Step forward and get next item.
  172. |                 NextCargo : Get next item with cargo.
  173.                   Prev      : Step backward and get previous item.
  174. |                 PrevCargo : Get previous item with cargo.
  175.                   Count     : Return the number of items in the list.
  176.                   Position  : Return line position of this item.
  177.                   Reset     : Reset the item pointer to the beginning.
  178.       ----------- --------------------------------------------------------
  179.       ARGUMENT    Init      : Fill array with valid arguments.
  180.       (clplist)   Find      : Locate a specific argument.
  181.                   Overflow  : Returns TRUE if there were more arguments
  182.                               than could fit in memory.
  183.       ----------- --------------------------------------------------------
  184.       WILD        Init      : Fill the array with filenames that match the
  185.       (argument)              filename mask.
  186.       ----------- ---------------------------------------------------